import utils from "utils";
import atlist from "components/mainChat/components/atList/atList.vue";
import animation from "components/animation/animation.vue";
import sendFriendCard from "components/mainChat/components/sendFriendCard/sendFriendCard.vue";
import getCaretCoordinates from "textarea-caret";
import { emojis } from "components/emoji";

export default {
  data() {
    return {
      content: "", //字符串+表情图片等
      ifEmojiShow: false,
      emojis: emojis,
      ifCutImgShow: false,
      atListPos: {},
      atSelection: {},
      atSelectVal: "",
      atList: [],
      emojiData:[],
      atSelectIndex: 0,
      clipUrl: "",
      newWorkStatus: undefined,
      preventInput: false,
      currentEmoji:0,
      emojiSize:25,
      emojiNum:1,
      emojiMax:1,
      
      lastSendTime : new Date()
    };
  },
  created() {
    //删除指定表情
    this.$bus.$on('deleteEmoji',id=>{
      let index = this.emojiData.findIndex(val=>val.id === id);
      if(index>-1) {
        this.emojiData.splice(index,1);
      }
    });
    //表情框关闭
    this.$bus.$on('emojiClose',()=>{
      this.ifEmojiShow = false;
    });
    //是否打开了多个页面
    this.$bus.$on("preventInput", () => {
      this.preventInput = true;
      clearTimeout(this.timer);
      this.timer = setTimeout(() => {
        this.preventInput = false;
      }, 1000 * 8);
    });
    //选中回复文字
    this.$bus.$on("replayText", text => {
      let { textarea } = this.$refs;
      this.content += text+`\n`;
      textarea.focus();
    });
    //确定@的联系人列表
    this.$bus.$on("sureAt", obj => {
      let { content, atSelectIndex, atSelectVal} = this,
        { textarea } = this.$refs,
        end = atSelectIndex + atSelectVal.length,
        val = obj.name + " ";

      this.content = content.substring(0, atSelectIndex) + val + content.substring(end);
      this.atList.push({
        name: obj.name,
        wxid: obj.wxid
      });
      this.atSelectVal = "";
      this.$nextTick(()=>{
        textarea.focus();
      });
    });

    this.newWorkStatus = navigator.onLine;
  },
  computed: {
    talkerList() {
      return this.$store.state.chat[`chats-${this.curRobotId}`] || [];
    },
    selectedUser() {
      let {curSessionKey, talkerList} = this;
      let chat = talkerList.find(item => item.chatId == curSessionKey);
      return chat;
    },
    enterShow() {
      let {selectedUser} = this;
      let onOff = selectedUser&&selectedUser.botInfo;
      return onOff;
    },
    // 过滤后的会话列表
    curSessionKey() {
      return this.$store.state.commonQuery.curSessionKey;
    },
    isCurRobotCanUse() {
      if(!this.$store.state.commonQuery.curTalker || !this.$store.state.commonQuery.curTalker.botInfo)return;
      let _tempRobot = this.$store.state.robotStatus.robotList.find( item => 
        item.robotId === (this.$store.state.commonQuery.curTalker.botInfo.robotId || this.$store.state.commonQuery.curTalker.botInfo.robotKey)
        &&
        item.robotWxid === this.$store.state.commonQuery.curTalker.botInfo.wxid
      );
      return _tempRobot && (_tempRobot.isUse || _tempRobot.robotStatus==1)
    },
    //群还是好友
    isGroup() {
      return this.$store.state.commonQuery.curTalker.isGroupChat;
    },
    curRobotId() {
      return this.$store.state.commonQuery.curRobot.robotId;
    },
    atListShow() {
      return this.$store.state.componentStatus.atListShow;
    },
    atListData() {
      let {isGroup,curRobotId} = this,atListData,
          curMember = this.$store.state.commonQuery.curMember;
      if (isGroup && curRobotId != "0") {
        atListData = (curMember && curMember.memberList) || {};
      }
      return atListData || {};
    },
    ifSendFriendCardShow() {
      return this.$store.state.componentStatus.ifSendFriendCardShow;
    },
  },
  watch: {
    curSessionKey(val) {
      let {selectedUser,talkerList} = this;
      if (selectedUser && selectedUser.botInfo && talkerList.length) {
        let draftObj = this.$store.state.robotStatus[`draft-${selectedUser.botInfo.robotKey}`];
        if (draftObj && draftObj[selectedUser.chatId]) {
          this.content = draftObj[selectedUser.chatId].content;
        } else {
          this.content = "";
        }
      };
      this.$nextTick(()=>{
        this.$refs.textarea.focus();
      });
      this.atList = [];
    },
    //如果切换当前会话时候文本框有内容，那就需要保存为草稿
    content(newVal) {
      let {selectedUser} = this;
      this.$store.dispatch("changeDraft", {
        robotKey: selectedUser.botInfo.robotId,
        // talkerWxid: selectedUser.curTalker.talkerWxid,
        talkerWxid: selectedUser.chatId,
        content: newVal,
        isDraft: Boolean(newVal),
        // isTopSession: selectedUser.body.isTopSession
        isTopSession: 0,
      });
    },
    ifEmojiShow(val) {
      if(val) {
        this.getEmoji();
      }else{
        this.emojiSize = 25;
        this.emojiNum = 1;
        this.emojiMax = 1;
        this.emojiData = [];
      }
    }
  },
  mounted() {
    document.getElementById("textArea").addEventListener("paste", e => {
      //处理目标容器（id）的paste事件
      if (
        e.clipboardData &&
        e.clipboardData.items[0].type.indexOf("image") > -1
      ) {
        this.clipFile = e.clipboardData.items[0].getAsFile();
        if (this.beforeUpload(this.clipFile)) {
          let file = new FileReader();
          file.onload = e => {
            this.clipUrl = e.target.result;
          };
          file.readAsDataURL(this.clipFile);
        }
      }
    });
    window.addEventListener("online", () => {
      this.newWorkStatus = true;
    });
    window.addEventListener("offline", () => {
      this.newWorkStatus = false;
    });
  },
  methods: {
    //切换表情类型
    emojiChange(index) {
      this.currentEmoji = index;
    },
    textAreaClick($event) {
      this.ifEmojiShow = false;
      this.atFn($event);
    },
    //关闭粘贴框
    copyClose() {
      this.clipUrl = "";
    },
    //选择表情
    selectEmoji(emoji) {
      console.log("emoji",emoji);
      let { textarea } = this.$refs;
      this.content += "[" + emoji.title + "]";
      this.ifEmojiShow = false;
      textarea.focus();
      this.$bus.$emit("postTrack", "wyxk_body_right_middle", 4);
    },
    sendMsg(event) {  
      if (!this.content || !this.content.replace(/[\n|\s]/g, "")) {
        this.content = "";
        return false;
      }
      if (event.ctrlKey && event.keyCode == 13) {
        this.content += "\n";
        return false;
      }
      this.sendToFriendOrGroup();
    },
    //递归替换文本里面的表情
    replaceTxtWithCode(targetArr, content) {
      if (targetArr.length == 0) {
        return content;
      }
      let _tempCont = "";
      for (let j = 0; j < targetArr.length; j++) {
        _tempCont = content.replace(targetArr[j].mark, targetArr[j].code);
        targetArr.shift();
        return this.replaceTxtWithCode(targetArr, _tempCont);
      }
    },
    //粘贴框确定后发送文件
    sendClip() {
      let { clipUrl, clipFile } = this;
      const isLarge = clipFile.size > 52428800,
            guid = new Date().valueOf(); //utils.guid();

      if (!isLarge) {
        clipFile.fileUrl = clipUrl;
        clipFile.isPicture = true;
        this.ajax(clipFile, guid);
        this.copyClose();
      }
    },
    //发送文件
    ajax(file, guid) {
      //发送ajax到后台
      const xhr = new XMLHttpRequest(),
        formdata = new FormData(),
        _that = this,
        { selectedUser } = this;

      selectedUser.robotId = this.curRobotId;
      let data = {
        uid: guid,
        fileUrl: file.fileUrl,
        fileSize: file.size,
        name: file.name,
        ...selectedUser,
        isPicture: file.isPicture,
        isMP4: file.isMP4
      };

      this.initFile(data); //初始化文件;
      formdata.append("files", file);
      formdata.append("messageId", guid);
      formdata.append("fileType", 7);
      xhr.open(
        "POST",
        this.CONFIG.basePath + "/merchant/upload.htm?token=" + this.TOKEN,
        true
      );
      xhr.onload = function() {
        if (xhr.status < 200 || xhr.status >= 300) {
          //上传失败
          console.error('文件上传失败')
          return;
        }
        // 图片上传成功
        let responseObj = JSON.parse(xhr.responseText);
        file.response = responseObj;
        file.uid = guid;
        _that.uploadSuccessHandler(file, selectedUser);
      };
      xhr.onerror = function() {
        _that.uploadErrorHandler(guid, selectedUser);
      }
      xhr.send(formdata);
    },
    //选择文件
    fileChange(ev) {
      let event = ev || window.event,
        target = ev.target || ev.srcElement,
        fileList = Array.from(target.files) || [];

      target.value = '';
      this.fileDeal(fileList);
    },
    //发送前验证大小和个数
    beforeUpload(fileList) {
      let isLarge = false;
      if(!Array.isArray(fileList)) {
        fileList = [fileList];
      }
      if(fileList.length>9) {
        this.$message.error("一次最多只能发送9个附件");
        return false;
      }
      isLarge = fileList.some(val=>{
        return val.size > 52428800;
      });
      if (isLarge) {
        this.$message.error("上传附件大小不能超过50MB");
      } 
      this.$bus.$emit("postTrack", "wyxk_body_right_middle", 5);
      return !isLarge;
    },
    //判断是否视频文件
    isMP4(name) {
      let Transfer = name.toUpperCase();
      if(Transfer.endsWith(".MP4") || 
        Transfer.endsWith(".OGG") || 
        Transfer.endsWith(".WEBM")) {
        return true;
      }else {
        return false;
      }
    },
    //判断是否图片
    isPicture(name) {
      let Transfer = name.toUpperCase();
      if (
        Transfer.endsWith(".JPEG") ||
        Transfer.endsWith(".JPG") ||
        Transfer.endsWith(".PNG") ||
        Transfer.endsWith(".SVG") ||
        Transfer.endsWith(".GIF") ||
        Transfer.endsWith(".ICO")
      ) {
        return true;
      } else {
        return false;
      }
    },
    //发送文件初始化
    initFile(data) {
      let messageId = data.uid;
      let send_obj = {
        body: {
          isSelf: "1", //我发给别人
          content: {
            fileUrl: data.fileUrl || "",
            fileName: data.name,
            fileSize: data.fileSize
          },
          isSendSuccess: "", //标识是否发送成功
          formTime: utils.formatHM(new Date()),
          msgType: "File", //1是文本，其他类型的未做处理
          messageId,
          timeZone:utils.getTimeZone(),
          timeStamp: utils.formatTime(new Date()),
          msgNotifyStatus: data.msgNotifyStatus,
          isTopSession: data.isTopSession
        },
        robotId: data.robotId,
        curTalker: data,        //TODO 可以精简下，按格式传   @linwl
      };

      if (data.isPicture) {
        send_obj.body.msgType = 7;
      }
      if(data.isMP4) {
        send_obj.body.msgType = 5;
      }
      //保存发送对方的信息
      let obj = {
        key: messageId,
        robotKey: data.robotId,
        friends: data.chatId,
        status: true
      };
      this.$store.dispatch("changeFileData", obj);
      this.$bus.$emit("scrollToBottom", 1);
      data = null;
    },
    //上传图片失败
    uploadErrorHandler(uid, selectedUser) {
      let obj = this.$store.state.commonQuery.sendFileData[uid],
        robotKey = obj.robotKey || selectedUser.robotId,
        friends = obj.friends || selectedUser.curTalker.talkerWxid;
      
        let _temp = {
        robotKey,
        friends: [friends],
        messageId: uid,
        code: 1
      };
      // this.$store.dispatch("updateSelfInfo", _temp);
    },
    //上传图片成功回调
    uploadSuccessHandler(file, selectedUser) {
      let { response } = file;
      if (response.code == "1") {
        let data = response.body.model;
        let obj = this.$store.state.commonQuery.sendFileData[file.uid];
        let robotKey = obj.robotKey || selectedUser.robotId;
        let chatId = obj.friends || selectedUser.curTalker.chatId;

        //获得图片路径后改变聊天数据对应的内容
        let _temp = {
          robotKey,
          chatId: chatId,
          messageId: data.messageId,
          fileUrl: data.fileUrl
        };
        // this.$store.dispatch("updateSelfInfo", _temp);
        //发送websockt
        this.sendFile(_temp, file);
      } else {
        this.uploadErrorHandler(file.uid, selectedUser);
      }
    },
    //xhr发送文件成功后调用微信接口
    sendFile(data, file) {
      //发送文件
      let query = {
        messageId: data.messageId,
        message:{},
        chatId: data.chatId,
        // robotKey: data.robotKey,
        // token: this.TOKEN
      };

      if(file.isMP4){
        query.message.contentType = 5;
        query.message.fileName = data.fileUrl;
      } else if (file.isPicture) {
        query.message.contentType = 7;
        query.message.pic = data.fileUrl;
        // query.type = "robot.msg.send";
        // query.pic = data.fileUrl;
        // query.content = "";
        // query.isDirect = "1";
      } else {
        query.message.contentType = 8;
        query.message.fileName = data.fileUrl;
        // query.type = "robot.file.delivery";
        // query.fileName = data.fileUrl;
      }

      this.$bus.$emit("sendMsg", query);

      let { selectedUser } = this;
      //插入自己发送中的信息
      this.$store.dispatch("newMessage", {
        messageId: data.messageId,
        timestamp: new Date().valueOf(),
        chatId: selectedUser.chatId,
        robotKey: selectedUser.botInfo.robotKey,
        chatUser: selectedUser.chatUser,
        chatName: selectedUser.chatName,
        isGroupChat: selectedUser.isGroupChat,
        assignTo: selectedUser.assignTo,
        isSendSuccess: '',        //发送中
        from: {
          contactId: selectedUser.botInfo.wxid,
          nickName: selectedUser.botInfo.nickName,
          headImg: selectedUser.botInfo.headImg,
          isGroupContact: selectedUser.isGroupChat
        },
        content: query.message,
      });      
    },
    //发送朋友或群
    sendToFriendOrGroup() {
      if((new Date() - this.lastSendTime) < 800){
        alert('发送太快了，休息一下吧~（发送间隔1s）');
        return;
      }

      let messageId = utils.getTimestamp();
      //发送文本消息
      let _tempContent = "";
      let { selectedUser } = this;
      // if (this.content.includes("[") && this.content.includes("]")) {
      //   let targetArr = emojis.filter(item => this.content.includes(item.mark));
      //   let str = this.replaceTxtWithCode(targetArr, this.content);
      //   _tempContent = str;
      // } else {
        _tempContent = this.content;
      // }

      //处理@字段
      let { atList } = this, atUserList = [];
      let self_tempContent = _tempContent;
      atList.forEach(val => {
        let validText = val.name.includes('@') ? val.name : `@${val.name}`;
        // _tempContent = validText;
        if (_tempContent.includes(validText)) {
          atUserList.push(val.wxid);
          atUserList = [...new Set(atUserList)];
        }
        _tempContent = _tempContent.replace(validText,"");
        _tempContent=_tempContent.trim()
      });
      const query = {
        "message":{
            "contentType": 1,
            "content": `${_tempContent}`,
            "atUserList": `${atUserList ? atUserList.join(',') : ''}`,      //TODO 待实现at功能
        },
        "chatId": selectedUser.chatId,
        messageId,
      };

      this.$bus.$emit("sendMsg", query);

      //插入自己发送中的信息
      this.$store.dispatch("newMessage", {
        messageId,
        timestamp: new Date().valueOf(),
        chatId: selectedUser.chatId,
        robotKey: selectedUser.botInfo.robotKey,
        chatUser: selectedUser.chatUser,
        chatName: selectedUser.chatName,
        isGroupChat: selectedUser.isGroupChat,
        assignTo: selectedUser.assignTo,
        isSendSuccess: atUserList.length,        //是否显示发送中。TODO 20201016 由于@消息没有回调确认消息，暂时将发送@消息，直接置为发送成功
        from: {
          contactId: selectedUser.botInfo.wxid,
          nickName: selectedUser.botInfo.nickName,
          headImg: selectedUser.botInfo.headImg,
          isGroupContact: selectedUser.isGroupChat
        },
        content: {contentType: query.message.contentType, atUserList: query.message.atUserList, content: self_tempContent},
      });
      
      this.lastSendTime = new Date();
      
      // let tmpMsg = new Date().valueOf() + 'aaa';
      // this.$store.dispatch("newChat", {"chatId":"S:1688853470612751_1688853470365500","chatUser":"1688853470365500","chatName":"蔺文龙(亮声)","chatHeadImg":"http://wework.qpic.cn/bizmail/b6jUeg5ToiaarAXNwz34lzvr2kCgibVqrnhSUQ1BibmU93ymbqZYGKTvA/0","isGroupChat":0,"lastMsgActive":1595582599000,"unreadCount":93,"botInfo":{"robotKey":"12bfc9ed0e404d98a8af6da198c96f66","wxid":"1688853470612751","nickName":"亮声","headImg":"http://mfile.yjiyun.com/merchant/robot/anonymousUser/d1969fb76f8d49be8884a7ee34f27ac0/2020031120215700000003.png","robotStatus":1},"pushContent":`蔺文龙：${tmpMsg}`,"assignTo":"16666666666"});
      // this.$store.dispatch("newMessage", {"messageId":`${new Date().valueOf()}`,"msgSvrID":"1062944","timestamp":1595582599000,"robotKey":"12bfc9ed0e404d98a8af6da198c96f66","chatId":"S:1688853470612751_1688853470365500","chatUser":"1688853470365500","chatName":"蔺文龙(亮声)","from":{"contactId":"1688853470365500","nickName":"蔺文龙","headImg":"http://wework.qpic.cn/bizmail/b6jUeg5ToiaarAXNwz34lzvr2kCgibVqrnhSUQ1BibmU93ymbqZYGKTvA/0","isGroupContact":0},"isGroupChat":0,"content":{"contentType":1,"content":`${tmpMsg}`},"assignTo":"16666666666"});

      $("#textArea").val("");
      this.content = "";
      this.atList = [];

      //清除掉草稿
      this.$store.dispatch("changeDraft", {
        robotKey: selectedUser.botInfo.robotKey,
        talkerWxid: selectedUser.chatId,
        isDraft: false
      })
      
      // 定时30秒后失败
      let timer = setTimeout(() => {
        let _temp = {
          messageId, 
          robotKey: selectedUser.botInfo.robotKey,
          chatId: selectedUser.chatId,
        };
        this.$store.dispatch("updateSelfInfo", _temp);
        this.$bus.$emit("limitSend", { messageId, status: 0 });
      }, 15000);
      this.$bus.$emit("limitSend", { messageId, timer, status: 1 });

      this.$bus.$emit("scrollToBottom", 1);
      this.$store.dispatch("changeAtListStatus", false);
      // this.$bus.$emit("postTrack", "wyxk_body_right_middle", 6);     //统计
    },
    //keydown事件
    keydown(e) {
      let { keyCode } = e,
        { atListShow } = this,
        { atList } = this.$refs;
      
      if (atListShow) {
        switch (keyCode) {
          case 13:      //回车
            e.preventDefault();
            atList.sureAt();
            break;
          case 38:      //向上
            e.preventDefault();
            atList.curSelect(-1);
            break;
          case 40:      //向下
            e.preventDefault();
            atList.curSelect(1);
            break;
        }
        return;
      }
      if (keyCode == 13) {      //回车
        e.preventDefault();
        this.sendMsg(e);
        if(this.clipUrl) {
          this.sendClip()
        }
      }
      if(this.content.length>=1){
        return
      }else{
        if([38,40].includes(keyCode)){
          let {curSessionKey, talkerList} = this;
          let chatIndex = talkerList.findIndex(item => item.chatId == curSessionKey);
          if(keyCode == 38 && chatIndex==0)return;      //首行
          if(keyCode == 40 && (chatIndex+1)==talkerList.length)return;      //尾行
  
          if(keyCode==40){
            chatIndex = chatIndex + 1;
          }
          else{
            chatIndex = chatIndex - 1;
          }
          this.$bus.$emit('selectThisSession',    talkerList[chatIndex]);
        }
      }
    },
    //@控制函数
    atFn(e) {
      let { target } = e,
        { value } = target,
        curPos = target.selectionStart - 1;
      if (!this.isGroup) {
        return;
      }
      if (!value) {
        this.$store.dispatch("changeAtListStatus", false);
      }
      for (let i = curPos; i >= 0; i--) {
        if (value.charAt(i) == " ") {
          this.$store.dispatch("changeAtListStatus", false);
          break;
        }
        //TODO 群的@
        if (value.charAt(i) === "@") {
          let pos = getCaretCoordinates(target, target.selectionEnd);
          pos.top -= target.scrollTop;
          this.atListPos = pos;
          this.atSelectVal = value.substring(i + 1, curPos + 1);
          this.atSelectIndex = i + 1;
          this.$store.dispatch("changeAtListStatus", true);
          break;
        } else {
          this.$store.dispatch("changeAtListStatus", false);
          break;
        }
      }
    },
    //阻止默认事件
    stop(e) {
      // let ev = e || window.event;
      e.preventDefault();
      e.stopPropagation();
    },
    //拖拽上传
    dropLoad(e) {
      let ev = e || window.event,
          fileList = Array.from(e.dataTransfer.files)||[];

      this.fileDeal(fileList);
    },
    //多个文件处理函数
    fileDeal(fileList) {
      var go;
      if(this.beforeUpload(fileList)) {
        go = eachFile.call(this,fileList);
        go.next();
      };

      function * eachFile(fileList) {
        for(let i=0;i<fileList.length;i++) {
          let file = yield deal.call(this,fileList[i]);
          this.ajax(file,utils.guid());
        }
      }

      function deal(val) {
        if(this.isPicture(val.name)) {
          let fileReader = new FileReader();
          fileReader.onload = e=>{
            val.isPicture = true;
            val.fileUrl = e.target.result;
            setTimeout(()=>{
              go.next(val);
            },500);
          }
          fileReader.readAsDataURL(val);
        }else{
          val.isPicture = false;
          val.fileUrl = '';
          val.isMP4 = false;
          if(this.isMP4(val.name)) {
            val.isMP4 = true;
          }
          setTimeout(()=>{
            go.next(val);
          },500);
        }
      }
    },
    //获取表情
    getEmoji() {
      let {emojiSize,emojiNum} = this;
      let offset = emojiSize * (emojiNum - 1);
      // this.robotserver.get('emoticon/list',{
      //   query:{
      //     offset,
      //     size:emojiSize
      //   }
      // }).then(data=>{
      //   if(data.code === '0') {
      //     let detail = data.data||[];
      //     this.emojiData = this.emojiData.concat(detail);
      //     this.emojiMax = Math.ceil(data.total / emojiSize);
      //   }else{
      //     this.$message.error('表情包获取失败，请刷新重试');
      //   }
      // }).catch(err=>{
      //   this.$message.error('表情包获取失败，请刷新重试');
      // });
    },
    //发送表情
    sendEmoji(emoji) {
      let { selectedUser } = this;
      let textarea = this.$refs.textarea;
      let guid = utils.guid();
      selectedUser.robotId = this.curRobotId;
      let data = {
        uid: guid,
        fileUrl: emoji.location,
        fileSize: 0,
        name: '',
        ...selectedUser,
        isPicture:true,
        isMP4:false
      };
      let _temp = {
        robotKey:selectedUser.robotId,
        friends: selectedUser.curTalker.chatId,
        messageId: data.uid,
        fileUrl: data.fileUrl
      };
      this.initFile(data); //初始化文件;
      //发送websockt
      this.sendFile(_temp, {});
      //关闭表情框
      this.ifEmojiShow = false;
      textarea.focus();
    },
    //显示菜单
    showMenu(ev, data) {
      this.$store.dispatch("changeMenuStatus", false);
      let pos = {
        left: ev.clientX,
        top: ev.clientY
      };
      let temp = Object.assign({},data);
      delete temp.type;
      this.$store.dispatch("changeMenuStatus", true);
      this.$store.dispatch("changeMenuData", Object.assign({ type: "emoji" },temp,pos));
    },
    //表情滚动加载
    emojiScroll(ev) {
      let e = ev || window.event;
      let target = e.target,
          targetH = target.scrollHeight - target.offsetHeight,
          { emojiMax,emojiNum } = this;
      if(target.scrollTop === targetH && emojiNum < emojiMax ) {
        ++this.emojiNum;
        this.getEmoji();
      }
    },
    // 发送好友名片
    onSendFriendCard(event) {
      this.$store.dispatch("changeIfSendFriendCardShow", true);
    },
  },
  beforeDestroy () {
    this.$bus.$off('emojiClose');
    this.$bus.$off('preventInput');
    this.$bus.$off('replayText');
    this.$bus.$off('sureAt');
  },
  components: {
    sendFriendCard,
    atlist,
    animation
  }
};